package com.hy.utils;

import java.util.HashMap;
import java.util.List;

public class ResultUtil extends HashMap<String, Object> {

	public static ResultUtil ok() {
		ResultUtil resultUtil = new ResultUtil();
		// 自定义状态
		resultUtil.put("code", "success");
		// 状态说明
		resultUtil.put("msg", "成功");
		return resultUtil;
	}

	public static ResultUtil error(String message) {
		ResultUtil resultUtil = new ResultUtil();
		// 自定义状态
		resultUtil.put("code", "error");
		// 状态说明
		resultUtil.put("msg", message);
		return resultUtil;
	}
	public static ResultUtil ok(int count,int limit,List list) {
		ResultUtil resultUtil = new ResultUtil();
		// 自定义状态
		resultUtil.put("code", "success");
		// 状态说明
		resultUtil.put("msg", "成功");
		int shuLiang = (int) Math.ceil(count / Double.valueOf(limit));
		resultUtil.put("data", list);
		resultUtil.put("total", count);
		return resultUtil;
	}
	public static ResultUtil ok(String name) {
		ResultUtil resultUtil = new ResultUtil();
		// 自定义状态
		resultUtil.put("code", "success");
		// 状态说明
		resultUtil.put("msg", "成功");
		
		resultUtil.put("name", name);
		
		return resultUtil;
	}

	// 失败的结果 登录
	public static ResultUtil error(String code, String message) {
		ResultUtil resultUtil = new ResultUtil();
		// 自定义状态
		resultUtil.put("code", code);
		// 状态说明
		resultUtil.put("msg", message);
		return resultUtil;
	}

	@Override
	// 重写put
	public ResultUtil put(String key, Object value) {
		super.put(key, value);
		return this;
	}

}
